package com.chuanye.jiguangimdemo.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanye.jiguangimdemo.R;

import java.util.List;

import cn.jpush.im.android.api.model.UserInfo;

public class ContactAdapter extends BaseAdapter {
    private Context mContext;
    private List<UserInfo> userInfoList;

    public ContactAdapter(Context mContext, List<UserInfo> userInfoList) {
        this.mContext = mContext;
        this.userInfoList = userInfoList;
    }

    @Override
    public int getCount() {
        return userInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return userInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_contact_view,null);
            holder.itmecontact_head_icon_iv = convertView.findViewById(R.id.itmecontact_head_icon_iv);
            holder.itmecontact_name_tv = convertView.findViewById(R.id.itmecontact_name_tv);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.itmecontact_head_icon_iv.setImageResource(R.drawable.rc_default_portrait);
        holder.itmecontact_name_tv.setText(userInfoList.get(position).getUserName());

        return convertView;
    }


    public static class ViewHolder{
        ImageView itmecontact_head_icon_iv;
        TextView itmecontact_name_tv;

    }
}
